package com.sesxh.project.knowledge.router;

import java.util.Map;
import java.util.Optional;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import com.sesxh.frame.core.data.DataSet;
import com.sesxh.frame.web.controller.BaseController;
import com.sesxh.project.knowledge.biz.model.Category;
import com.sesxh.project.knowledge.biz.service.ICategoryService;
@Controller 
@RequestMapping("/knowledge/category")
public class CategoryController implements BaseController {

	
	@Autowired
	private ICategoryService categoryService;
	
    @RequestMapping(value="/loadCategoryDataSet", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public @ResponseBody  Object loadCategoryDataSet(@RequestParam Map<String,Object> params){
	    DataSet dataSet=  categoryService.loadCategoryDataSet(params);
	    return ajaxQuery("dataSet", dataSet);
    }
	
    @RequestMapping(value="/createCategory", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public  @ResponseBody Object createCategory(Category category){
		categoryService.createCategory(category);
    	return ajaxDoneSuccess("数据操作成功 ");
    }
	
    @RequestMapping(value="/loadCategory", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public @ResponseBody  Object loadCategory(Long id){
		Optional<Category> ops = categoryService.loadCategoryById(id);
		return ajaxQuery("category",ops);
    }
	
    @RequestMapping(value="/updateCategory", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public @ResponseBody  Object updateCategory(Category category){
		categoryService.updateCategory(category);
		return ajaxDoneSuccess("数据操作成功 ");
    }
	
    @RequestMapping(value="/deleteCategory", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public @ResponseBody  Object deleteCategory(Long id){
		categoryService.deleteCategory(id);
		return ajaxDoneSuccess("数据操作成功 ");
    }

}